#include<string>
#include<unordered_map>
#include<algorithm>
using namespace std;

class Solution {
public:
    string fractionToDecimal(int numerator, int denominator) {
        if (numerator == 0 || denominator == 0)
            return "0";
        string res = "";
        if (numerator < 0 ^ denominator < 0)
            res += "-";
        long long remainder = numerator;
        long long fractor = denominator;
        remainder = abs(remainder);
        fractor = abs(fractor);
        while (remainder > fractor) {
            res += to_string(remainder / fractor);
            remainder %= fractor;
        }
        if (res == "") res += "0";
        if (remainder == 0) return res;
        res += ".";
        unordered_map<long long, int> map;
        remainder = remainder * 10;
        while (remainder != 0) {
            if (map.find(remainder) != map.end()) {
                res.insert(map[remainder]-1, "(");
                res += ")";
                break;
            }
            res += to_string(remainder / fractor);
            map[remainder] = res.length();
            remainder = remainder % fractor;
            remainder = remainder * 10;
        }
        return res;
    }
};

//int main() {
//    Solution sol;
//    sol.fractionToDecimal(-2147483648, 1);
//}